<?php
class Dependencia extends AppModel {
	var $name = 'Dependencia';
	var $displayField = 'descripcion';
	function generateCodigo(){
		$result = $this->query('select 
									COALESCE(cast(max(d.codigo) as integer)+1,1) as "Dependencia__codigo" 
								from expedientes.dependencias d 
								where d.activo = true');
		$result = $result[0];
		return str_repeat('0',4-strlen($result['Dependencia']['codigo'])).$result['Dependencia']['codigo'];			
	}		
}
?>